package com.example.factory;

import com.example.entity.Animal;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * 饿汉式获取对象
 */
public class LastAnimalFactory {
    private static final Map<String, Object> map = new HashMap<>();

    static {
        Properties p = new Properties();
        try {
            p.load(LastAnimalFactory.class.getResourceAsStream("animal_impl.properties"));
            for (Object o : p.keySet()) {
                map.put((String) o, Class.forName((String) p.get(o)).newInstance());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public Object getBean(String className) {
        return map.get(className);
    }
}
